from Goldenberry.optimization.ga.GbSolutionRepMgr.EncoderFactory import EncoderFactory
from Goldenberry.optimization.ga.GbSolutionRepMgr.ISolutionRepMgt import ISolutionRepMgt
from Goldenberry.optimization.ga.GbSolutionRepMgr.ISolutionRepSetup import ISolutionRepSetup
import numpy as np

class SolutionRep(ISolutionRepMgt, ISolutionRepSetup):
    """description of class"""
    def __init__(self, encode_function, range_min, range_max):
        self.__encoder = EncoderFactory().get_encoder(encode_function, range_min, range_max)
        self.encode_function = encode_function

    #Override methods of ISolutionRepMgt
    def encode(self, population):
        for x in range(0, len(population)):
            population[x].genotype = self.__encoder.encode_phenotype(population[x].params)
        return population

    def decode(self, population):
        for x in range(0, len(population)):
            population[x].params = self.__encoder.decode_genotype(population[x].genotype)
        return population

    #Override methods of ISolutionRepSetup
    def get_range_min(self):
        return self.range_min

    def set_range_min(self, range_min):
        self.range_min = range_min

    def get_range_max(self):
        return self.range_max

    def set_range_max(self, range_max):
        self.range_max = range_max

    def get_solution_domain(self):
        return self.solution_domain

    def set_solution_domain(self, solution_domain):
        self.solution_domain = solution_domain

    def get_encode_function(self):
        return self.encode_function

    def set_encode_function(self, encode_function):
        self.encode_function = encode_function
        
